package model
{
	
	import mx.collections.ArrayCollection;
	
	import vo.Answers;
	import vo.Question;
	import vo.User;
	
	
	[Bindable]
	public class MentorMatchModelLocator 
	{
		private static var modelLocator : MentorMatchModelLocator;
		
		public static const MASTER_VIEW_NOT_LOGGED_IN : String = "loginView";
		public static const MASTER_VIEW_LOGGED_IN : String = "allQuestionView";
		
		public var questionAC:ArrayCollection;
		public var currentQuestion:int;
		public var user:User;
		public var numberOfQuestions:int;
		
		public static function getInstance() : MentorMatchModelLocator
		{
			if (modelLocator == null)
			{
				modelLocator = new MentorMatchModelLocator();
			}
			return modelLocator;
		}
		
		
		public function MentorMatchModelLocator()
		{
			if( modelLocator != null )
			{
				throw new Error("Only one Mentor match model locator instance should be instantiated");
			}
			else{
				init();
			}
			
		}
		public function checkLoginStatus():void
		{
			if(!user.logged)
			{
				masterNavigationStateString = MASTER_VIEW_NOT_LOGGED_IN;
			}
			else
			{
				masterNavigationStateString = MASTER_VIEW_LOGGED_IN;
			}
			
		}
		private function init():void
		{
					
			fillQuestionAc();
			currentQuestion=0;
			user=new User();
			user.fillUser("Bob","John",0);
			checkLoginStatus();
		}
		
		public function advanceCurrentQuestion():void
		{
			currentQuestion++;
		}
		
		public function getCurrentQuestion():Question
		{
			return questionAC[currentQuestion];
		}
		
		public function getNumberOfQuestions():int
		{
			return numberOfQuestions;		
		}
		public function getCurrent():int
		{
			return currentQuestion;
		}
		public function addQuestion():void
		{
			var question:Question = new Question();
			var answer1:Answers = new Answers(0, "default"); 
			var answer2:Answers = new Answers(1, "default");
			var answer:ArrayCollection = new ArrayCollection();
			answer.addItem(answer1);
			answer.addItem(answer2);
			question.fillQuestion(0,"default", answer);
			
			questionAC.addItem(question);
		}
		private function fillQuestionAc():void
		{
			var question1:Question = new Question();
			var answer11:Answers = new Answers(0, "mike"); 
			var answer12:Answers = new Answers(1, "greg");
			var answer13:Answers = new Answers(2, "mansur");
			var answer14:Answers = new Answers(3, "fadi");
			var answer15:Answers = new Answers(4, "Matt");
			var answer16:Answers = new Answers(5, "tyson");
			
			var answer1:ArrayCollection = new ArrayCollection();
			answer1.addItem(answer11);
			answer1.addItem(answer12);
			answer1.addItem(answer13);
			answer1.addItem(answer14);
			answer1.addItem(answer15);
			answer1.addItem(answer16);
			
			question1.fillQuestion(0,"What is your name?", answer1);
			numberOfQuestions++;


			////////////////////////////////
			var question2:Question = new Question();
			var answer21:Answers = new Answers(0, "red"); 
			var answer22:Answers = new Answers(1, "blue");
			var answer23:Answers = new Answers(2, "oragne");
			var answer24:Answers = new Answers(3, "sdlfkj");
			
			var answer2:ArrayCollection = new ArrayCollection();
			answer2.addItem(answer21);
			answer2.addItem(answer22);
			answer2.addItem(answer23);
			answer2.addItem(answer24);
			
			question2.fillQuestion(1,"What is your favorite color?", answer2);
			numberOfQuestions++;
			
			var ac:ArrayCollection = new ArrayCollection;
			ac.addItem(question1);
			ac.addItem(question2);
			
			questionAC = ac;
		}
	
	public var masterNavigationStateString:String;
	
	
	public var practices:Array = [{label:"", data:0},
			{label:"Java Practice -- we rock!", data:1},
			{label:"Microsoft Practice -- like the evil empire!", data:2},
			{label:"BA/PM Practice -- we like to make word docs!", data:3},
			{label:"Database Practice -- we do it on tables!", data:4},
			{label:"PLM Practice -- No one really knows what we do!", data:5},
			{label:"Sales Practice -- Selling stuff we cant explain everyday!", data:6},
			{label:"Management Practice -- we dont do the work, we wanna manage the work!", data:7}];
	
	
	}
}